package com.zx.idc.backend.gui.slog.service;

import com.zx.idc.backend.gui.api.commom.entity.UploadModel;
import com.zx.idc.backend.gui.api.commom.template.NIdcFtpTemplate;
import com.zx.idc.backend.gui.api.management.basicdata.report.IdcBasicMonitorDataReportService;
import com.zx.idc.common.attributes.FTPReportDataTypeEnum;
import com.zx.idc.common.attributes.SchemaFileNameEnum;
import com.zx.idc.common.attributes.WebServiceInterfaceParamEnum;
import com.zx.idc.ds.base.oper.service.IBaseOperCompanyService;
import com.zx.idc.ds.common.constant.ReportStatusConstant;
import com.zx.idc.ds.slog.entity.ReportData;
import com.zx.idc.ds.slog.entity.SlogAbnormalIp;
import com.zx.idc.ds.slog.entity.SlogAbnormalIpStatus;
import com.zx.idc.ds.slog.service.ISlogAbnormalIpService;
import com.zx.idc.ds.slog.service.ISlogAbnormalIpStatusService;
import com.zx.idc.ds.sys.service.ISysConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.zx.idc.common.attributes.NetCommunicationFileTypeEnum.MONITOR_DATA;

@Service
@Transactional(rollbackFor = Exception.class)
public class SlogAbnormalIpInterfaceService {
    @Autowired
    private ISlogAbnormalIpService service;
    @Autowired
    private NIdcFtpTemplate nIdcFtpTemplate;
    @Autowired
    private IdcBasicMonitorDataReportService idcBasicMonitorDataReportService;
    @Autowired
    private ISlogAbnormalIpStatusService slogAbnormalIpStatusService;

    @Autowired
    private IBaseOperCompanyService iBaseOperCompanyService;

    public Boolean reportData(ReportData reportData) {
        //TODO 待客户确认
        return null;
    }

    public void insertReport(Long id) {
        final String idcId = iBaseOperCompanyService.getIdcId();
        service.updateById(new SlogAbnormalIp().setId(id).setReportStatus(ReportStatusConstant.REPORTING));
        slogAbnormalIpStatusService.updateById(
            new SlogAbnormalIpStatus()
                .setAbnormalIpId(id)
                .setReportStatus(ReportStatusConstant.REPORTING)
        );

        nIdcFtpTemplate.uploadXMLFile(
            new UploadModel<>(
                idcBasicMonitorDataReportService.slogIllegalSiteAddReport(id, idcId),
                SchemaFileNameEnum.BASE_DATA_EXCEPTION_DATA_REPORT,
                FTPReportDataTypeEnum.FTP_BASE_DATA,
                MONITOR_DATA
            )
        );
    }
}
